<?php

namespace app\admin\model\keesuishoupai;

use think\Model;
class Report extends Model
{
    // 表名
    protected $name = 'keesuishoupai_report';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'isopen_text',
        'createtime_text',
        'reviewtime_text',
        'solvetime_text',
        'images_array',
    ];
    public function getLevelList()
    {
        $config = get_addon_config('keesuishoupai');
        return $config['levels'];
    }
    public function getStatusList()
    {
        return [-1=> __('Status -1'),'0' => __('Status 0'), '1' => __('Status 1')];
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = isset($data['status']) ? $data['status'] : '';
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getIsopenList()
    {
        return ['0' => __('Isopen 0'), '1' => __('Isopen 1')];
    }
    public function getIsopenTextAttr($value, $data)
    {
        $value = isset($data['isopen']) ? $data['isopen'] : '';
        $list = $this->getIsopenList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getCreatetimeTextAttr($value, $data)
    {
        $value = !empty($data['createtime']) ? $data['createtime'] : '';
        return $value ? date("Y-m-d H:i:s", $value) : '-';
    }

    public function getReviewTimeTextAttr($value, $data)
    {
        $value = !empty($data['reviewtime']) ? $data['reviewtime'] : '';
        return $value ? date("Y-m-d H:i:s", $value) : '-';
    }

    public function getSolvetimeTextAttr($value, $data)
    {
        $value = !empty($data['solvetime']) ? $data['solvetime'] : '';
        return $value ? date("Y-m-d H:i:s", $value) : '-';
    }

    public function getImagesArrayAttr($value, $data)
    {
            $images_array = $data['images'] ? explode(",",$data['images']) : [];
            if(empty($images_array)) return $images_array;
            foreach($images_array as $key => $val){
                $images_array[$key] = cdnurl($val,true);
            }
            return $images_array;
    }
    public function reviewadmin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'review_admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function solveadmin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'solve_admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
